package com.manopservice.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.manopservice.model.CarAppearance;

@Repository("carAppearanceDAO")
public class CarAppearanceDAOImpl implements CarAppearanceDAO{

	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public void save(CarAppearance carAppearance) {
		sessionFactory.getCurrentSession().saveOrUpdate(carAppearance);
		
	}

	@Override
	public void delete(int id) {
		CarAppearance carAppearance = (CarAppearance) sessionFactory.getCurrentSession().get(CarAppearance.class, id);
		sessionFactory.getCurrentSession().delete(carAppearance);
		
	}

	@SuppressWarnings("unchecked")
	public List<CarAppearance> findAll() {
		
		return (List<CarAppearance>) sessionFactory.getCurrentSession().createCriteria(CarAppearance.class).list();
	}

	@Override
	public CarAppearance findById(int id) {

		return (CarAppearance) sessionFactory.getCurrentSession().get(CarAppearance.class, id);
	}

}
